package sourcePackage;

import javax.swing.*;

import java.sql.*;
import java.awt.event.*;

public class Button_Menu extends JPanel implements ActionListener  
{
	protected JButton b1, b2, b3, b4;
	protected JLabel label1;
	protected static Log_In login;
	private static int TaskNumber = 0;
	
	public Button_Menu() throws SQLException
	{
		login = new Log_In();
		
        label1 = new JLabel("Assignment 4: Data Mining", JLabel.CENTER);
        //Set the position of its text, relative to its icon:
        label1.setVerticalTextPosition(JLabel.TOP);
        label1.setHorizontalTextPosition(JLabel.CENTER);
        add(label1);
        
        b1 = new JButton("Task 1");
		b1.setVerticalTextPosition(AbstractButton.TOP);
		b1.setHorizontalTextPosition(AbstractButton.LEADING);
		b1.setMnemonic(KeyEvent.VK_1);
		b1.setActionCommand("task1");
		b1.addActionListener(this);
		
		b2 = new JButton("Task 2");
		b2.setVerticalTextPosition(AbstractButton.TOP);
		b2.setHorizontalTextPosition(AbstractButton.TRAILING);
		b2.setMnemonic(KeyEvent.VK_2);
		b2.setActionCommand("task2");
		b2.addActionListener(this);
		
		b3 = new JButton("Task 3");
		b3.setVerticalTextPosition(AbstractButton.BOTTOM);
		b3.setHorizontalTextPosition(AbstractButton.LEADING);
		b3.setMnemonic(KeyEvent.VK_3);
		b3.setActionCommand("task3");
		b3.addActionListener(this);
		
		b4 = new JButton("Task 4");
		b4.setVerticalTextPosition(AbstractButton.BOTTOM);
		b4.setHorizontalTextPosition(AbstractButton.TRAILING);
		b4.setMnemonic(KeyEvent.VK_4);
		b4.setActionCommand("task4");
		b4.addActionListener(this);
		
		add(b1);
		add(b2);
		add(b3);
		add(b4);
		
		
		//Display Log_In
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() 
            {
     	       //Create and set up the window.
                JFrame frame = new JFrame("Log In");
                frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

                //Create and set up the content pane.
                Log_In newContentPane = new Log_In();
                newContentPane.setOpaque(true); //content panes must be opaque
                frame.setContentPane(newContentPane);

                //Display the window.
                frame.pack();
                frame.setVisible(true);
                
            }
        });

		
	}
	
//	public static int getTaskNumber()
//	{
//		return TaskNumber;
//	}
//	public void setTaskNumber(int number)
//	{
//		TaskNumber = number;
//	}
	public void actionPerformed(ActionEvent e)
	{
		if("task1".equals(e.getActionCommand()))
		{
			setTaskNumber(1);
			javax.swing.SwingUtilities.invokeLater(new Runnable() {
		            public void run() 
		            {
		    			//Open task1 pane
		    			JFrame frame1 = new JFrame("Task 1");
		    			
		    			//Create and setup new content pane
		    			Text_Entry Text_EntryTask1;
						try {
							Text_EntryTask1 = new Text_Entry("At what support do you want to mine the Frequent Itemsets?");
			    			Text_EntryTask1.setOpaque(true);
			    			frame1.setContentPane(Text_EntryTask1);
			    			
			    			//Display the window
			    			frame1.pack();
			    			frame1.setVisible(true);
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

		            }
		        });

		}
		else if("task2".equals(e.getActionCommand()))
		{
			setTaskNumber(2);
			javax.swing.SwingUtilities.invokeLater(new Runnable() {
		            public void run() 
		            {
		    			//Open task1 pane
		    			JFrame frame2 = new JFrame("Task 2");
		    			
		    			//Create and setup new content pane
		    			Text_Entry Text_EntryTask2;
						try {
							Text_EntryTask2 = new Text_Entry("At what support do you want to mine the Frequent Itemsets? (pairs)");
			    			Text_EntryTask2.setOpaque(true);
			    			frame2.setContentPane(Text_EntryTask2);
			    			
			    			//Display the window
			    			frame2.pack();
			    			frame2.setVisible(true);
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

		            }
		        });
		}
		else if("task3".equals(e.getActionCommand()))
		{
			//Open task3 pane
		}
		else if("task4".equals(e.getActionCommand()))
		{
			//Open task4 pane
		}
		else
		{
			//Error on action event / Do nothing
		}
	}
	
	private static void createAndShowGUI() throws SQLException
	{
		//Create and setup the window
		JFrame frame = new JFrame("CIS4301 Assignment 4 - David Moore and Tui Popenoe");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		//Create and setup the content pane
		Button_Menu newContentPane = new Button_Menu();
		newContentPane.setOpaque(true);
		frame.setContentPane(newContentPane);
		
		//Display Window
		frame.pack();
		frame.setVisible(true);
	}
	
	public static void main(String[] args)
	{
		//Schedule a job for event-dispatching thread
		javax.swing.SwingUtilities.invokeLater(new Runnable()
		{
			public void run()
			{
				try {
					//login.createAndShowGUI();
					createAndShowGUI();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}

	public static int getTaskNumber() {
		return TaskNumber;
	}

	public static void setTaskNumber(int taskNumber) {
		TaskNumber = taskNumber;
	}	
}

